using UnityEngine;

public class DailyBonusItem : MonoBehaviour
{
	public int dailyindex;

	public UIEventListener claimbtn;

	public UILabel titlename;

	public UISprite getrewardsp;

	public UILabel getnumlabel;

	public UISprite selectsp;

	public UISprite yessp;

	public TweenScale yesanima;

	public BonusData curbonusdata;

	private int curday;

	private void Start()
	{
		claimbtn.onClick = OnClickClaimBtn;
	}

	public void enable(int index, BonusData data, int dayco, int alday)
	{
		curday = dayco;
		dailyindex = index;
		curbonusdata = data;
		titlename.text = "Day" + (index + 1);
		if (index != 6)
		{
			switch (data.type)
			{
			case 0:
				getrewardsp.spriteName = "GY_zuanShi_03";
				getrewardsp.SetDimensions(66, 48);
				getrewardsp.transform.localPosition = new Vector3(0f, -5.5f, 0f);
				getnumlabel.text = string.Empty + data.num;
				break;
			case 1:
				getrewardsp.spriteName = "CZ_jinBi_02";
				getrewardsp.SetDimensions(60, 46);
				getrewardsp.transform.localPosition = new Vector3(0f, -5f, 0f);
				getnumlabel.text = string.Empty + data.num;
				break;
			case 3:
				if (data.num == 4)
				{
					getrewardsp.spriteName = "GY_SP_0";
					getrewardsp.SetDimensions(58, 52);
					getrewardsp.transform.localPosition = new Vector3(0f, -5f, 0f);
					getnumlabel.text = "3";
				}
				else if (data.num == 131)
				{
					getrewardsp.spriteName = "ZB_duoMuBiaoDaoDan_02";
					getrewardsp.SetDimensions(74, 37);
					getrewardsp.transform.localPosition = new Vector3(0f, -5f, 0f);
					getnumlabel.text = "M_Through";
				}
				break;
			}
		}
		else
		{
			switch (data.type)
			{
			case 0:
				getrewardsp.spriteName = "GY_zuanShi_03";
				getrewardsp.SetDimensions(80, 58);
				getrewardsp.transform.localPosition = new Vector3(0f, -5.5f, 0f);
				getnumlabel.text = string.Empty + data.num;
				break;
			case 1:
				getrewardsp.spriteName = "CZ_jinBi_02";
				getrewardsp.SetDimensions(80, 62);
				getrewardsp.transform.localPosition = new Vector3(0f, -5f, 0f);
				getnumlabel.text = string.Empty + data.num;
				break;
			case 3:
				if (data.num == 131)
				{
					getrewardsp.spriteName = "ZB_duoMuBiaoDaoDan_02";
					getrewardsp.SetDimensions(102, 51);
					getrewardsp.transform.localPosition = new Vector3(0f, -5f, 0f);
					getnumlabel.text = "M_Through";
				}
				break;
			}
		}
		if (dayco == -1)
		{
			if (alday >= index)
			{
				yessp.enabled = true;
			}
			return;
		}
		if (alday == index)
		{
			selectsp.enabled = true;
		}
		if (alday > index)
		{
			yessp.enabled = true;
		}
	}

	public void OnClickClaimBtn(GameObject btn)
	{
		if (selectsp.enabled)
		{
			Platform.SetBonusCount();
			yessp.enabled = true;
			yesanima.PlayForward();
			selectsp.enabled = false;
			switch (curbonusdata.type)
			{
			case 0:
				MonoInstance<AudioController>.instance.play(AudioType.UI_getdiamond, 0f);
				MenuPlayerprefs.instance.AddDiamod(curbonusdata.num, late: true);
				MenuUIController.instance.enable_effectui(getrewardsp.transform.position, 1);
				break;
			case 1:
				MonoInstance<AudioController>.instance.play(AudioType.UI_getmoney, 0f);
				MenuPlayerprefs.instance.AddMoney(curbonusdata.num, late: true);
				MenuUIController.instance.enable_effectui(getrewardsp.transform.position, 0);
				break;
			case 3:
				MonoInstance<AudioController>.instance.play(AudioType.UI_equiped, 0f);
				if (curbonusdata.num == 4)
				{
					MenuPlayerprefs.instance.addpiece(0, 3);
				}
				else if (curbonusdata.num == 131)
				{
					MenuPlayerprefs.instance.save_multiple_bonus();
				}
				break;
			}
			if (Platform.GetBonusAlreadyGot() == 6)
			{
				MenuPlayerprefs.instance.setbonusfirst(2);
			}
			Platform.flurryEvent_main(0, curday);
			MenuUIController.instance.mainui.dis_dailyhint();
		}
		else if (curbonusdata.type == 3 && curbonusdata.num == 4)
		{
			MenuUIController.instance.enable_pieceui(MenuDataController.instance.piecedata[0]);
		}
	}
}
